package com.orangecy.flowengine.flow;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import java.util.Map;

/**
 * @Author : orangeCy.奕
 * @Time : 2021/9/12
 * @desc : 猎豹养成产品源码
 * 流程管理
 */
public class FlowManager {

    /**
     * 维护每套流程集合,一个流程包括一个流程身份flowId,以及流程各个组件封装流程定义对象
     */
    private static Map<Long,FlowDefinition> bizFlowMap = Maps.newHashMap();

    static {
        //批量修改标题
        FlowDefinition titleDefine = FlowDefinition.builder()
                .paramsValidators(Lists.newArrayList("itemParamValidator"))
                .bizAssemble(Lists.newArrayList("itemEntityAssemblyComponent"))
                .bizValidators(Lists.newArrayList("itemBizValidator"))
                .bizExecs(Lists.newArrayList("itemTitleExecComponent"))
                .build();
        bizFlowMap.put(FlowIdEnum.BATCH_EDIT_TITLE.getCode(),titleDefine);
        /**
         * 可以做到拔插式,不一定七个流程每个都需要有执行,可选择
         */
    }

    public static FlowDefinition getFlowDefine(Long flowId) {
        FlowDefinition flowDefinition = bizFlowMap.get(flowId);
        if(null == flowDefinition) {
            throw new RuntimeException();
        }
        return flowDefinition;
    }
}